class Solution {
    public static int minOperations(int[] nums, int x) {
        int left = 0,right = 0,sum = 0,target = 0,n = nums.length,tmp = 0,len = -1;
        for(int i = 0; i < n; i++) {
            sum += nums[i];
        }
        /*if(sum == x) {
            return n;
        }*/
        target = sum - x;
        while(right < n) {
            tmp += nums[right];
            while(tmp > target) {
                tmp -= nums[left++];
            }
            if(tmp == target) {
                len = Math.max(len,right - left + 1);
            }
            right++;
        }
        if(len == -1) {
            return -1;
        }
        return n - len;
    }

    public static void main(String[] args) {
        int[] arr = {8828,9581,49,9818,9974,9869,9991,10000,10000,10000,9999,9993,9904,8819,1231,6309};
        int count = minOperations(arr,134365);
        System.out.println(count);
    }
}